﻿Ext.require([
    'Twi.Msg',
    'Twi.QuickAjax',
    'BIM.store.User'
]);

Ext.onReady(function () {
    Ext.apply(Ext.form.field.VTypes, {
        password: function (val, field) {
            if (field.initialPassField) {
                var pwd = field.up('form').down('#' + field.initialPassField);
                return (val == pwd.getValue());
            }
            return true;
        },

        passwordText: '两次输入密码不相同，请重新输入！'
    });
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';
    twiSelf.init();
});

Twi.TAB.EditPwd = {

    Vars: {
        pwdform: null,
        userMappingName: 'SM010'
    } //end Vars

    , init: function () {

        twiVars.pwdform = Ext.create('Ext.form.Panel', {
            renderTo: 'pwedit',
            //frame: true,
            bodyPadding: '5 5 0',
           
            fieldDefaults: {
                labelWidth: 125,
                msgTarget: 'side',
                autoFitErrors: false
            },
            defaults: {
                width: 300,
                inputType: 'password'
            },
            defaultType: 'textfield',
            items: [
            {
             fieldLabel: '原始密码',
                name: 'oldpass',
                itemId: 'oldpass',
                allowBlank: false
            },
            {
                fieldLabel: '新密码',
                name: 'pass',
                itemId: 'pass',
                allowBlank: false,
                listeners: {
                    validitychange: function (field) {
                        field.next().validate();
                    },
                    blur: function (field) {
                        field.next().validate();
                    }
                }
            }, {
                fieldLabel: '再输新密码',
                name: 'pass-cfrm',
                vtype: 'password',
                  allowBlank: false,
                initialPassField: 'pass' // id of the initial password field
            }],
            buttons: [{
            text: '修改',
            handler: function () {
         
                if (this.up('form').getForm().isValid()) {

                   var oldpwd= this.up('form').getForm().findField('oldpass').getValue();
                   var newpwd= this.up('form').getForm().findField('pass').getValue();
                    Twi.QuickAjax.Ajax({
                        params: {
                            cn: 'Authority',
                            mn: 'TAB',
                            mn2: 'EditPwd',
                            TableName: twiVars.userMappingName,
                            oldpwd: oldpwd,
                            newpwd: newpwd
                        },
                        success: function (obj) {
                      
                        Twi.Msg.Info('温馨提示', obj.data);
                       
                        }
                });

            }

          //  this.up('form').getForm().reset();

            }
        },{
            text: '重置',
            handler: function() {
                this.up('form').getForm().reset();
            }
        }]
        });
    
    } //end init;

};       //end Twi.TAB.EditPwd

var twiSelf = Twi.TAB.EditPwd;
var twiVars = twiSelf.Vars;


